import React, {Component} from 'react'
import ReactDOM from 'react-dom'

class App extends Component{
    state = {
        count: 0
    }

    // 使用函数箭头函数绑定
    onIncrement = () => {
        // 使用setState函数才能修改初始化的state
        this.setState({
            count: this.state.count + 1
        })
    }

    render() {
        return (
            <div>
                <h1>计算机：{ this.state.count }</h1>
                <button onClick={this.onIncrement}>+1·</button>
            </div>
        )
    }
}

ReactDOM.render(<App/>, document.getElementById('root'))